'use strict'

const Koa = require('koa');
const path = require('path');
const wechat = require('./wechat/g');
const util = require('./lib/utils');
const wechat_file = path.join(__dirname, './config/wechat.txt')

const config = {
  wechat: {
    appID: 'wx62713f1fb1a44a6f',
    appSecret: '716f0a2cd79aeeded1725e35e5e58617',
    token: 'wx2019test',
    getAccessToken: function() {
      return util.readFileAsync(wechat_file);
    },
    saveAccessToken: function(data) {
      data = JSON.stringify(data);
      return util.writeAccessToken(wechat_file, data);
    },
  }
}

const app = new Koa();

app.use(wechat(config.wechat));

app.listen('3000', () => {
  console.log('server running at port 3000');
});
